﻿
Imports System.Configuration
Imports System.Data.Common

Imports Moca.Db

Public Class Sys

    Private Shared _instance As Sys

    Public Shared ReadOnly Property Instance() As Sys
        Get
            If _instance Is Nothing Then
                _instance = New Sys
            End If
            Return _instance
        End Get
    End Property

    Public Function GetConnectionStrings() As ConnectionStringSettings
		Return ConfigurationManager.ConnectionStrings("MiYABiS.EntityCodeGenerator.My.MySettings.DB")
    End Function

	Public Function GetConnectionStringsNames() As String()
		Dim ary As New ArrayList
		Dim enume As IEnumerator
		enume = ConfigurationManager.ConnectionStrings.GetEnumerator
		While enume.MoveNext
			Dim css As ConnectionStringSettings
			css = enume.Current
			ary.Add(css.Name)
		End While
		Return DirectCast(ary.ToArray(GetType(String)), String())
	End Function

	Public Function GetConnectionStrings(ByVal key As String) As ConnectionStringSettings
		Return ConfigurationManager.ConnectionStrings(key)
	End Function

    ''' <summary>
    '''  Sql Connection
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getSqlConnection() As String
        Dim builder As DbConnectionStringBuilder
        Dim buf As Object = Nothing
        Dim sqlConnectionSettings As ConnectionStringSettings

        builder = New DbConnectionStringBuilder

        sqlConnectionSettings = GetConnectionStrings()
        builder.ConnectionString = sqlConnectionSettings.ConnectionString

        Return sqlConnectionSettings.ConnectionString
    End Function

End Class
